﻿Imports System
Imports System.Collections.Specialized
Imports System.Collections.Generic

Namespace GoogleAnalyticsMailHandler
    Public Class Email
        Public Property Headers() As NameValueCollection
            Get
                Return m_Headers
            End Get
            Protected Set(ByVal value As NameValueCollection)
                m_Headers = Value
            End Set
        End Property
        Private m_Headers As NameValueCollection
        Public Property ContentType() As String
            Get
                Return m_ContentType
            End Get
            Protected Set(ByVal value As String)
                m_ContentType = Value
            End Set
        End Property
        Private m_ContentType As String
        Public Property UtcDateTime() As DateTime
            Get
                Return m_UtcDateTime
            End Get
            Protected Set(ByVal value As DateTime)
                m_UtcDateTime = Value
            End Set
        End Property
        Private m_UtcDateTime As DateTime
        Public Property FromContact() As String
            Get
                Return m_From
            End Get
            Protected Set(ByVal value As String)
                m_From = value
            End Set
        End Property
        Private m_From As String
        Public Property ToContact() As String
            Get
                Return m_To
            End Get
            Protected Set(ByVal value As String)
                m_To = value
            End Set
        End Property
        Private m_To As String
        Public Property CcContact() As String
            Get
                Return m_Cc
            End Get
            Protected Set(ByVal value As String)
                m_Cc = value
            End Set
        End Property
        Private m_Cc As String
        Public Property Subject() As String
            Get
                Return m_Subject
            End Get
            Protected Set(ByVal value As String)
                m_Subject = Value
            End Set
        End Property
        Private m_Subject As String
        Public Property EmailId() As Integer
            Get
                Return m_EmailId
            End Get
            Protected Set(ByVal value As Integer)
                m_EmailId = Value
            End Set
        End Property
        Private m_EmailId As Integer
        Public Property MsgParts() As List(Of MessagePart)
            Get
                Return m_MsgParts
            End Get
            Set(ByVal value As List(Of MessagePart))
                m_MsgParts = Value
            End Set
        End Property
        Private m_MsgParts As List(Of MessagePart)
        Public Property Providers() As List(Of Provider)
            Get
                Return m_Providers
            End Get
            Protected Set(ByVal value As List(Of Provider))
                m_Providers = Value
            End Set
        End Property
        Private m_Providers As List(Of Provider)

        Public Property Site() As [String]
            Get
                Return m_Site
            End Get
            Set(ByVal value As [String])
                m_Site = Value
            End Set
        End Property
        Private m_Site As [String]
        Public Property Type() As [String]
            Get
                Return m_Type
            End Get
            Set(ByVal value As [String])
                m_Type = Value
            End Set
        End Property
        Private m_Type As [String]
        Public Property StartDate() As DateTime
            Get
                Return m_StartDate
            End Get
            Set(ByVal value As DateTime)
                m_StartDate = Value
            End Set
        End Property
        Private m_StartDate As DateTime
        Public Property EndDate() As DateTime
            Get
                Return m_EndDate
            End Get
            Set(ByVal value As DateTime)
                m_EndDate = Value
            End Set
        End Property
        Private m_EndDate As DateTime

        Public Sub New(ByVal emailText As String, ByVal emailId__1 As Integer)
            Providers = New List(Of Provider)()
            MsgParts = New List(Of MessagePart)()
            EmailId = emailId__1

            Headers = Util.ParseHeaders(emailText)
            ContentType = Headers("Content-Type")
            FromContact = Headers("From")
            ToContact = Headers("To")
            Subject = Headers("Subject")
            CcContact = Headers("CC")
            If Headers("Date") IsNot Nothing Then
                Try
                    UtcDateTime = Util.ConvertStrToUtcDateTime(Headers("Date"))
                Catch generatedExceptionName As FormatException
                    UtcDateTime = DateTime.MinValue
                End Try
            Else
                UtcDateTime = DateTime.MinValue
            End If
        End Sub
    End Class
End Namespace
